package com.wechat.dto;

import java.io.Serializable;
import java.util.List;

import com.alibaba.fastjson.annotation.JSONField;
import com.swak.Constants;
import com.swak.entity.Page;
import com.swak.persistence.Classify;
import com.swak.security.Principal;
import com.swak.utils.Lists;
import com.swak.utils.bean.BeanCopier;
import com.swak.utils.bean.BeanCopiers;
import com.wechat.entity.Chat;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.Accessors;

/**
 * 聊天
 * 
 * @author Auto Generator
 * @date 2022-10-21T23:59:27.243629400
 */
@Getter
@Setter
@Accessors(chain = true)
@ToString
public class ChatDTO implements Serializable {

	private static final long serialVersionUID = 1L;

	@lombok.EqualsAndHashCode.Exclude
	private static final transient BeanCopier<ChatDTO, Chat> Copier = BeanCopiers.create(ChatDTO.class, Chat.class);

	private String id;
	private Byte type;
	private String nickName;
	private Integer chatOrder;
	private Integer unReadCount;
	private String lastMsgContent;
	private Byte lastMsgType;
	@JSONField(format = Constants.Second_Format)
	private java.time.LocalDateTime lastMsgDate;
	private Long lastMsgId;
	private Byte othersAtMe;
	private Long msgSequence;
	private Integer contactCount;
	private Byte isTop;
	private Byte isHide;
	private Byte isFriend;
	private Byte isAlert;
	private Byte isDnn;
	private Byte isDel;
	@JSONField(format = Constants.Second_Format)
	private java.time.LocalDateTime createDate;
	@JSONField(format = Constants.Second_Format)
	private java.time.LocalDateTime updateDate;
	@JSONField(format = Constants.Second_Format)
	private java.time.LocalDateTime delAt;

	/**
	 * 操作人的身份
	 */
	private Principal principal;

	/**
	 * 临时数据
	 */
	private ChatInputDTO draft;

	/**
	 * DTO 转换为 PO
	 *
	 * @param entity
	 * @return DTO
	 */
	public Chat transform() {
		return Copier.transform(this);
	}

	/**
	 * DTOS 转换为 POS
	 *
	 * @param dtos
	 * @return DTOs
	 */
	public static List<Chat> transform(List<ChatDTO> dtos) {
		List<Chat> pos = Lists.newArrayList();
		if (dtos == null) {
			return pos;
		}
		for (ChatDTO dto : dtos) {
			pos.add(dto.transform());
		}
		return pos;
	}

	/**
	 * PO 转换为 DTO
	 *
	 * @param entity
	 * @return DTO
	 */
	public static ChatDTO convert(Chat entity) {
		if (entity == null) {
			return null;
		}
		return Copier.convert(entity);
	}

	/**
	 * POS 转换为 DTOS
	 *
	 * @param entitys
	 * @return DTOs
	 */
	public static List<ChatDTO> convert(List<Chat> entitys) {
		List<ChatDTO> dtos = Lists.newArrayList();
		if (entitys == null) {
			return dtos;
		}
		for (Chat entity : entitys) {
			dtos.add(ChatDTO.convert(entity));
		}
		return dtos;
	}

	/**
	 * Page 转换为 Page
	 *
	 * @param entity
	 * @return DTO
	 */
	public static Page<ChatDTO> convert(Page<Chat> page) {
		return Page.of(page.getParam(), ChatDTO.convert(page.getData()));
	}

	/**
	 * classify 分类
	 *
	 * @param dtos
	 * @param pos
	 * @return Classify
	 */
	public static Classify<Chat> classify(List<ChatDTO> dtos, List<Chat> pos) {
		return Classify.of(ChatDTO.transform(dtos), pos);
	}

	/**
	 * 创建DTO
	 *
	 * @return DTO
	 */
	public static ChatDTO of() {
		return new ChatDTO();
	}
}
